package com.huaxin.hxcloud.find;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.huaxin.common.Entity.HxCommentStateBean;
import com.huaxin.hxcloud.R;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by hebing on 2017/8/8.
 */

public class HxCommentStateAdapter extends RecyclerView.Adapter<HxCommentStateAdapter.ViewHolder> {

    private       Context        mContext;
    private final LayoutInflater mInflater;
    List<HxCommentStateBean> mCommentSateBeanList;

    public HxCommentStateAdapter(Context context, List<HxCommentStateBean> commentSateBeanList) {
        this.mContext = context;
        this.mInflater = LayoutInflater.from(context);
        this.mCommentSateBeanList = commentSateBeanList;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.item_comment_state, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        final HxCommentStateBean sateBean = mCommentSateBeanList.get(position);
        holder.mTypeTv.setText(sateBean.getType());
        holder.mTypeDesTv.setText(sateBean.getTypeDes());
        if (sateBean.isCheck()) {
            holder.mSelectImg.setBackgroundResource(R.drawable.icon_check);
        }
        holder.mRvlayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listener.onItemClick(position);
                notifyDataSetChanged();
            }
        });
    }

    @Override
    public int getItemCount() {
        return mCommentSateBeanList == null ? 0 : mCommentSateBeanList.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.rv_layout)
        RelativeLayout mRvlayout;
        @BindView(R.id.type_tv)
        TextView       mTypeTv;
        @BindView(R.id.type_des_tv)
        TextView       mTypeDesTv;
        @BindView(R.id.select_img)
        ImageView      mSelectImg;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    public interface OnViewItemClickListener {
        void onItemClick(int position);
    }

    private OnViewItemClickListener listener;

    public void setOnItemClickListener(OnViewItemClickListener listener) {
        this.listener = listener;
    }
}
